package org.hackystat.sdsa.analyzer.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.hackystat.sdsa.analyzer.model.activity.Activity;
import org.hackystat.sdsa.service.resource.devstream.jaxb.ActivityTO;
import org.hackystat.sdsa.service.resource.devstream.jaxb.EpisodeTO;
import org.hackystat.sdsa.service.resource.devstream.jaxb.MacroBehavior;
import org.hackystat.sdsa.service.resource.devstream.jaxb.MicroBehavior;

/**
 * Defines episode that contains a list of activities.
 * 
 * @author hongbing
 *
 */
public class Episode {
  /** List of activities. */
  private List<Activity> activityList;
  /** Micro behavior in this episode. */
  private MicroBehavior microBehavior;
  /** Macro behavior in this episode. */
  private MacroBehavior macroBehavior;
  
  /**
   * Empty episode constructor.
   */
  public Episode() {
    this.activityList = new ArrayList<Activity>();    
  }

  /**
   * Gets the list of activities which is not modifiable by any client.
   * 
   * @return Activity list.
   */
  public List<Activity> getActivityList() {
    return Collections.unmodifiableList(activityList);
  }

  /**
   * Adds an activity into the list.
   * 
   * @param activity A new activity.
   */
  public void addActivity(Activity activity) {
    this.activityList.add(activity);
  }

  /**
   * Gets the number of activities in this episode.
   * 
   * @return Number of activities in this episode.
   */
  public int getActivityNum() {
    return this.activityList.size();
  }

  /**
   * Convert this episode object to a transfer object that can be sent back to client.
   * 
   * @return Transfer object of this episode.
   */
  public EpisodeTO toTransferObject() {
    EpisodeTO episodeTO = new EpisodeTO();
    
    List<ActivityTO> activityTOList = episodeTO.getActivityTO();
    for (Activity activity : this.activityList) {
      activityTOList.add(activity.toTransferObject());
    }
    
    episodeTO.setMicroBehavior(this.microBehavior);
    episodeTO.setMacroBehavior(this.macroBehavior);
    return episodeTO;
  }

  /**
   * Sets the micro behavior of this episode.
   * 
   * @param microBehavior Microbehavior in this episode.
   */
  public void setMicroBehavior(MicroBehavior microBehavior) {
    this.microBehavior = microBehavior; 
  }

  /**
   * Gets the micro behavior of this episode.
   * 
   * @return Microbehavior of this episode.
   */
  public MicroBehavior getMicroBehavior() {
    return this.microBehavior; 
  }

  /**
   * Sets macro behavior of this episode.
   * 
   * @param macroBehavior Macro behavior of this episode.
   */
  public void setMacroBehavior(MacroBehavior macroBehavior) {
    this.macroBehavior = macroBehavior;
  }
  
  /**
   * Gets macro behavior of this episode.
   * 
   * @return Macor behavior of this episode.
   */
  public MacroBehavior getMacroBehavior() {
    return this.macroBehavior;
  }

}
